package com.clock.album;

import ohos.agp.components.*;
import ohos.app.Context;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class ListFileAdapter extends RecycleItemProvider {
    protected Context context;
    private ArrayList<String> titleList = new ArrayList<>();
    private Map<String,ArrayList<Integer>> dataList=new HashMap<>();

    public ListFileAdapter(Context context,ArrayList<String> titleList ,Map<String,ArrayList<Integer>> dataList) {
        this.context = context;
        this.titleList=titleList;
        this.dataList=dataList;
        notifyDataChanged();
    }
    @Override
    public int getCount() {
        return titleList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public Component getComponent(int i, Component component, ComponentContainer componentContainer) {
        ViewHolder viewHolder;
        if(component==null){
            component = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_listfile_list_item,null,false);
            viewHolder=new ViewHolder();
            viewHolder.mNickname= (Text) component.findComponentById(ResourceTable.Id_list_nickname);
            component.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) component.getTag();
        }
        viewHolder.mNickname.setText(titleList.get(i)+"["+dataList.get(titleList.get(i)).size()+"]");
        return component;
    }
    public class ViewHolder{
        public Text mNickname;
    }
}
